package com.example.tys.baseapplication.NetModel.network;


import com.example.tys.baseapplication.NetModel.okhttp.NetOperationOkHttp;

/**
 * @author Administrator
 * @date 2016/10/26
 * 网络操作入口类
 * NetServer.<Response>getNetOperation().get();
 */
public class NetServer {
    private static INetOperation<?> netOperation;

    /**
     * 添加使用不同网络框架实现了INetOperation接口的类，默认是Okhttp3
     *
     * @param netOperation 实现了网络基本操作(INetOperation)的实体类
     */
    public static void setNetOperation(INetOperation netOperation) {
        NetServer.netOperation = null;
        NetServer.netOperation = netOperation;
    }

    public static <R> INetOperation<R> getNetOperation() {
        if (null == netOperation) {
            synchronized (NetServer.class) {
                if (null == netOperation) {
                    netOperation = new NetOperationOkHttp();
                }
            }
        }
        return (INetOperation<R>) netOperation;
    }
}
